﻿CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
PROJECT(NFMMOSnsCommonPlugin)

AUX_SOURCE_DIRECTORY(./ SRC)

if (CMAKE_BUILD_TYPE STREQUAL "Release")

    ADD_LIBRARY(${PROJECT_NAME} STATIC ${SRC})
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")

    ADD_LIBRARY(${PROJECT_NAME} STATIC ${SRC})
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicRelease")

    ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRC})
    # 只对 CMake 目标建立依赖关系（系统库和库文件名不是 CMake 目标）
    add_dependencies(${PROJECT_NAME} ${NFSHM_CORE_LIBS} ${NFSHM_SERVER_COMMON_LIBS} ${LIREN_GAME_COMMON_LIBS} NFMMOSnsCommon)
    # 动态库需要链接核心库、系统库和游戏逻辑库才能使用相关符号
    TARGET_LINK_LIBRARIES(${PROJECT_NAME} 
        ${NFSHM_CORE_LIBS} 
        ${NFSHM_SYSTEM_LIBS}
        ${NFSHM_SERVER_COMMON_LIBS} ${LIREN_GAME_COMMON_LIBS}
        NFMMOSnsCommon
    )
elseif (CMAKE_BUILD_TYPE STREQUAL "DynamicDebug")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")

    ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRC})
    # 只对 CMake 目标建立依赖关系（系统库和库文件名不是 CMake 目标）
    add_dependencies(${PROJECT_NAME} ${NFSHM_CORE_LIBS} ${NFSHM_SERVER_COMMON_LIBS} ${LIREN_GAME_COMMON_LIBS} NFMMOSnsCommon)
    # 动态库需要链接核心库、系统库和游戏逻辑库才能使用相关符号
    TARGET_LINK_LIBRARIES(${PROJECT_NAME} 
        ${NFSHM_CORE_LIBS} 
        ${NFSHM_SYSTEM_LIBS}
        ${NFSHM_SERVER_COMMON_LIBS} ${LIREN_GAME_COMMON_LIBS}
        NFMMOSnsCommon
    )
endif ()

# ============================================================================
# Install 配置
# ============================================================================
# 只有动态库版本才需要安装
if (CMAKE_BUILD_TYPE STREQUAL "DynamicRelease")
    install(TARGETS ${PROJECT_NAME}
            LIBRARY DESTINATION "Bin/DynamicRelease"
            RUNTIME DESTINATION "Bin/DynamicRelease"
            ARCHIVE DESTINATION "Bin/DynamicRelease")
elseif(CMAKE_BUILD_TYPE STREQUAL "DynamicDebug")
    install(TARGETS ${PROJECT_NAME}
            LIBRARY DESTINATION "Bin/DynamicDebug"
            RUNTIME DESTINATION "Bin/DynamicDebug"
            ARCHIVE DESTINATION "Bin/DynamicDebug")
endif()

